package com.atguigu.gmall0701.demo.customer.controller;

import com.atguigu.gmall0701.demo.customer.bean.Customer;
import com.atguigu.gmall0701.demo.customer.service.CustomerService;
import com.atguigu.gmall0701.demo.customer.service.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CustomerController {

    @Autowired
    @Qualifier("CustomerServiceA") //组件名称   如果接口只有一个实现类可以省略 ，如果有多个 必须加组件名称
    CustomerService customerService  ;

     //get
    // 接收请求路径中键值对的参数  （ 查询条件，辅助参数） 用于读  浏览器可见

    @RequestMapping(value = "/customer",method = RequestMethod.GET)
    public   List<Customer>  getCustomer(  @RequestParam("name") String name, @RequestParam(value = "age" ,required = false ,defaultValue = "0") Integer age ){
        List<Customer> customerList = customerService.getCustomerList(name, age);

        return  customerList;
    }


    //   路径中嵌入的参数 （ 主键，唯一标识)   用于读 浏览器可见
    @GetMapping(  "/customer/{id}.html")
    public  Customer  getCustomer(@PathVariable("id") String id  ){

        Customer customer = customerService.getCustomerById(id);
        return  customer;
    }

    //post
    //接收表单方式提交 //接收请求体
    @PostMapping("/customer")
    public  String  saveCustomer( @RequestBody Customer customer ){
        customerService.saveCustomer(customer);
        return "success";
    }




}
